package cn.edu.scau.cmi.yanghaorui.combination.consistent;

import java.util.ArrayList;
import java.util.Iterator;

import cn.edu.scau.cmi.yanghaorui.client.CombinationSafeClient;
import cn.edu.scau.cmi.yanghaorui.client.CombinationConsistentClient;
import cn.edu.scau.cmi.yanghaorui.combination.safe.SafeOrangization;
import cn.edu.scau.cmi.yanghaorui.combination.safe.SafeTeam;

public class ConsistentTeam extends ConsistentOrangization{
private ArrayList <ConsistentOrangization> org_list;
	
	public String sym_name;
	
	public ArrayList<ConsistentOrangization> getOrg_list() {
		return org_list;
	}

	public void setOrg_list(ArrayList<ConsistentOrangization> org_list) {
		this.org_list = org_list;
	}

	public ArrayList<ConsistentOrangization> getOrg_list2() {
		return org_list2;
	}

	public void setOrg_list2(ArrayList<ConsistentOrangization> org_list2) {
		this.org_list2 = org_list2;
	}

	private ArrayList <ConsistentOrangization> org_list2;
	
	private String saying=" ";
	private int number;
	//@Ovrreide
	public void add(ConsistentOrangization org) {
		if(org!=null) {
			org_list.add(org);
		}
	}
	
	public void delete(ConsistentOrangization org) {
		if(org!=null) {
			org_list.remove(org);
		}
	}
	public Iterator <ConsistentOrangization> elements(){//getChildren
		return org_list.iterator();
	}
	
	public ConsistentTeam() {
		org_list=new ArrayList <ConsistentOrangization>();
		org_list2=new ArrayList <ConsistentOrangization>();
		CombinationConsistentClient.team_num++;
		
		number=CombinationConsistentClient.team_num;
		//String temp="团队"+number;
		sym_name="团队"+number;
	}
	
	public String say2(ArrayList <ConsistentOrangization> org_list,ArrayList <ConsistentOrangization> org_list2) {
		int len=org_list.size();
		//CombinationSafeClient.team_num++;
		System.out.print("一致性组合模式:团队"+number +"，有以下成员:");
		for(int i=0;i<len;i++) {
			ConsistentOrangization org=org_list.get(i);
			//CombinationSafeClient.team_num++;
			 saying=" "+org.say()+" ";
			 System.out.print(saying);
			 //System.out.println("<<<<<"+i);
			 //org_list2.clear();
			 if(org.team_or_personal()==true) {
				 
				 org_list2.add(org);
				 //System.out.println("666");
			 }
		}
		System.out.print("\n");
		//System.out.println(org_list2.size());
		
		//while()
		if(org_list2.size()>0) {
			ArrayList <ConsistentOrangization> temp_list=new ArrayList <ConsistentOrangization>();
			ArrayList <ConsistentOrangization> temp_list2=new ArrayList <ConsistentOrangization>();
			temp_list2=org_list2;
			//System.out.println("666");
			for(int j=0;j<temp_list2.size();j++) {
				//SafeTeam st=(SafeTeam)temp_list.get(j);
				//System.out.println(temp_list2);
				if(temp_list2!=null&&temp_list2.size()>0) {
					((ConsistentTeam)temp_list2.get(j)).say2(((ConsistentTeam)temp_list2.get(j)).getOrg_list(),temp_list);
					//System.out.println("666");
				}
				
			}
			
		}
		
		
		return saying;
	}
	
	public int getSize() {
		return org_list.size();
	}

	@Override
	public boolean team_or_personal() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public String say() {
		String temp="团队"+number;
		sym_name=temp;
		// TODO Auto-generated method stub
		return temp;
	}

	@Override
	public void add() {
		// TODO Auto-generated method stub
		
	}

}
